home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / blanker / source / main.c < prev    next >
C/C++ Source or Header  |  1993-08-08  |  7KB  |  213 lines

  1. /*
  2.  *      Copyright (c) 1993 Michael D. Bayne.
  3.  *      All rights reserved.
  4.  *
  5.  *      Please see the documentation accompanying the distribution for distribution and disclaimer information.
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <exec/memory.h>
  10. #include <exec/ports.h>
  11.  
  12. #include <dos/dos.h>
  13. #include <dos/dostags.h>
  14.  
  15. #include <intuition/intuition.h>
  16. #include <intuition/intuitionbase.h>
  17. #include <workbench/startup.h>
  18. #include <workbench/workbench.h>
  19. #include <libraries/reqtools.h>
  20.  
  21. #include <clib/exec_protos.h>
  22. #include <clib/dos_protos.h>
  23. #include <clib/alib_protos.h>
  24. #include <clib/intuition_protos.h>
  25. #include <clib/graphics_protos.h>
  26. #include <clib/utility_protos.h>
  27. #include <clib/wb_protos.h>
  28.  
  29. #include <stdlib.h>
  30.  
  31. #include "Blanker.h"
  32. #include "Blanker_rev.h"
  33. #include "defs.h"
  34.  
  35. STATIC const UBYTE VersTag[] = VERSTAG;
  36.  
  37. #include "protos/cxhand.h"
  38. #include "protos/prefs.h"
  39. #include "protos/winhand.h"
  40. #include "protos/messaging.h"
  41. #include "protos/timer.h"
  42.  
  43. __far   extern  ULONG   RangeSeed;
  44.         LONG            blankSig, unblankSig, rc;
  45.         ULONG           tags[] = { RT_Window, 0L, RT_LockWindow, TRUE, TAG_END, 0L, TAG_END };
  46. struct  IntuitionBase   *IntuitionBase = 0L;
  47. struct  GfxBase         *GfxBase = 0L;
  48. struct  ReqToolsBase    *ReqToolsBase = 0L;
  49. struct  Library         *CxBase = 0L, *IconBase = 0L, *GadToolsBase = 0L, *UtilityBase = 0L, *WorkbenchBase = 0L,
  50.                         *IFFParseBase = 0L;
  51. struct  Task            *Task = 0L;
  52. struct  MsgPort         *blankerPort = 0L, *modulePort = 0L, *appWinPort = 0L;
  53. struct  AppWindow       *blankerAppWin = 0L;
  54. struct  RandomPrefsList *rPL = 0L;
  55. struct  BlankerPrefs    *bPrefs;
  56.  
  57. VOID closeMainWindow( VOID )
  58. {
  59.         while( blankerAppWin ) if( RemoveAppWindow( blankerAppWin )) blankerAppWin = 0L;
  60.         CloseBlankerWindow();
  61.         tags[1] = 0L;
  62. }
  63.  
  64. LONG openMainWindow( VOID )
  65. {
  66.         ULONG   lock, scr = 0;
  67.  
  68.         if( !BlankerWnd ) {
  69.                 if( SetupScreen()) return( 1 );
  70.                 OpenBlankerWindow();
  71.                 tags[1] = ( ULONG )BlankerWnd;
  72.                 CloseDownScreen();
  73.                 blankerAppWin = AddAppWindow( 1L, 0L, BlankerWnd, appWinPort, 0L );
  74.         } else {
  75.                 ActivateWindow( BlankerWnd );
  76.                 if( BlankerWnd->WScreen->FirstWindow != BlankerWnd ) WindowToFront( BlankerWnd );
  77.         }
  78.         if( !BlankerWnd ) return( QUIT );
  79.         else {
  80.                 lock = LockIBase( 0 );
  81.                 scr = ( IntuitionBase->FirstScreen != BlankerWnd->WScreen );
  82.                 UnlockIBase( lock );
  83.                 if( scr ) ScreenToFront( BlankerWnd->WScreen );
  84.         }
  85.         setPrefs( bPrefs, Blanker_CNT );
  86.         return( OK );
  87. }
  88.  
  89. VOID exitBlanker( LONG exitValue )
  90. {
  91.         struct Message *cleanMsg;
  92.  
  93.         if( modulePort ) sendModMsg( BM_DOQUIT, modulePort );
  94.  
  95.         closeMainWindow();
  96.  
  97.         if( bPrefs ) FreeVec( bPrefs );
  98.  
  99.         if( rPL ) {
  100.                 FreeRPList( rPL );
  101.                 FreeVec( rPL );
  102.         }
  103.  
  104.         if( appWinPort ) {
  105.                 while( cleanMsg = GetMsg( appWinPort )) ReplyMsg( cleanMsg );
  106.                 DeletePort( appWinPort );
  107.         }
  108.  
  109.         if( blankerPort ) DeletePort( blankerPort );
  110.  
  111.         ShutdownCX();
  112.  
  113.         FreeSignal( blankSig );
  114.  
  115.         if( IFFParseBase ) CloseLibrary( IFFParseBase );
  116.         if( UtilityBase ) CloseLibrary( UtilityBase );
  117.         if( WorkbenchBase ) CloseLibrary( WorkbenchBase );
  118.         if( ReqToolsBase ) CloseLibrary(( struct Library * )ReqToolsBase );
  119.         if( IconBase ) CloseLibrary( IconBase );
  120.         if( CxBase ) CloseLibrary( CxBase );
  121.         if( GfxBase ) CloseLibrary(( struct Library * )GfxBase );
  122.         if( GadToolsBase ) CloseLibrary( GadToolsBase );
  123.         if( IntuitionBase ) CloseLibrary(( struct Library * )IntuitionBase );
  124.  
  125.         exit( exitValue );
  126. }
  127.                 
  128. #ifdef DICE
  129. VOID Kludge( VOID ) { _waitwbmsg(); }
  130.  
  131. VOID main( int argc, char *argv[] )
  132. {
  133. extern  struct WBStartup        *_WBMsg;
  134.         struct WBStartup        *WBSMsg = _WBMsg;
  135. #else
  136. VOID main( int argc, char *argv[] )
  137. {
  138.         struct WBStartup        *WBSMsg = 0L;
  139. #endif
  140.     struct Task        *tTask = 0L;
  141.     struct MsgPort        *tmpPort = 0L;
  142.         struct AppMessage       *AppMsg;
  143.         ULONG                   sigs;
  144.         LONG                    retval = 1;
  145.  
  146.         if(!( IntuitionBase = ( struct IntuitionBase * )OpenLibrary( "intuition.library", 37L ))) exitBlanker( 1L );
  147.         if(!( GfxBase = ( struct GfxBase * )OpenLibrary( "graphics.library", 37L ))) exitBlanker( 1L );
  148.         if(!( GadToolsBase = OpenLibrary( "gadtools.library", 37L ))) exitBlanker( 1L );
  149.         if(!( CxBase = OpenLibrary( "commodities.library", 37L ))) exitBlanker( 1L );
  150.         if(!( IconBase = OpenLibrary( "icon.library", 36L ))) exitBlanker( 1L );
  151.         if(!( ReqToolsBase = ( struct ReqToolsBase * )OpenLibrary( REQTOOLSNAME, REQTOOLSVERSION ))) exitBlanker( 1L );
  152.         if(!( WorkbenchBase = OpenLibrary( WORKBENCH_NAME, 37L ))) exitBlanker( 1L );
  153.         if(!( UtilityBase = OpenLibrary( "utility.library", 37L ))) exitBlanker( 1L );
  154.         if(!( IFFParseBase = OpenLibrary( "iffparse.library", 37L ))) exitBlanker( 1L );
  155.  
  156.         if(!( bPrefs = AllocVec( sizeof( struct BlankerPrefs ), MEMF_CLEAR ))) exitBlanker( 2L );
  157.         if(!( rPL = AllocVec( sizeof( struct RandomPrefsList ), MEMF_CLEAR ))) exitBlanker( 2L );
  158.  
  159.         RangeSeed = (ULONG)( Task = FindTask( 0L ));
  160.  
  161.         if(( blankSig = ( ULONG )AllocSignal( -1L )) == -1 ) exitBlanker( 3L );
  162.         cxBlankFlag = 1L << blankSig;
  163.  
  164.         if( CheckCX() == QUIT ) exitBlanker( 3L );
  165.  
  166.         if(!( blankerPort = CreatePort( "BlankerCC", 0 ))) exitBlanker( 4L );
  167.         if(!( appWinPort = CreatePort( 0L, 0 ))) exitBlanker( 4L );
  168.  
  169.         rc = loadPrefsFromENVARC( bPrefs );
  170. #ifdef DICE
  171.         if( WBSMsg &&( WBSMsg->sm_NumArgs > 1 ))
  172. #else
  173.     if(( !argc )&&( WBSMsg = ( struct WBStartup * )argv )&&( WBSMsg->sm_NumArgs > 1 ))
  174. #endif
  175.         rc = loadPrefsFromWBArgList( &( WBSMsg->sm_ArgList[1] ), WBSMsg->sm_NumArgs-1, bPrefs );
  176.     if( rc ) prefError( rc );
  177.  
  178.     if( SetupCX() == QUIT ) exitBlanker( 5L );
  179.  
  180.         if( bPrefs->bp_PopUp ) retval = openMainWindow();
  181.  
  182.     while( retval ) {
  183.         sigs = Wait( cxBlankFlag | cxSigFlag | SIG_WIN | SIG_BREAK | SIG_APP );
  184.  
  185.                 if( sigs & cxBlankFlag ) {
  186.             if(( bPrefs->bp_RandTimeout )&&( tTask = bTask )&&( tmpPort = modulePort )) {
  187.                 bTask = 0L;
  188.                 modulePort = 0L;
  189.             }
  190.                         if( bPrefs->bp_Flags & BS_RANDOM ) loadRandPrefs( rPL, bPrefs );
  191.                         sendModMsg( BM_DOBLANK, modulePort );
  192.             if( tTask ) {
  193.                 Delay( 60 );
  194.                 Signal( tTask, SIGBREAKF_CTRL_C );
  195.                 sendModMsg( BM_DOQUIT, tmpPort );
  196.                 tTask = 0L;
  197.             }
  198.                 }
  199.                 if( sigs & cxSigFlag ) retval = handleCxMess();
  200.                 if( sigs & SIG_WIN ) retval = HandleBlankerIDCMP();
  201.                 if( sigs & SIG_BREAK ) retval = 0L;
  202.                 if( sigs & SIG_APP ) {
  203.                         if( AppMsg = ( struct AppMessage * )GetMsg( appWinPort )) {
  204.                                 loadPrefsFromWBArgList( AppMsg->am_ArgList, AppMsg->am_NumArgs, bPrefs );
  205.                                 ReplyMsg(( struct Message * )AppMsg );
  206.                         }
  207.                 }
  208.                 if( retval == CLOSEWIN ) closeMainWindow();
  209.         }
  210.  
  211.         exitBlanker( 0L );
  212. }
  213.